<?php // lab_info.php -- Display general lab information

// IP Address stuff

$ip=$_SERVER['REMOTE_ADDR'];
$subnet = explode (".", $ip);

/* Print toner levels, sorted by toner level (by default). We can also sort...
	
- Alphabetically by lab
- Geographically (will need to create our own sort algorithm for this, based on some general sense of distance)
- Alphabetically by building (will also require a unique algorithm) */

print "<p class=\"heading\">
	 You can sort the toner information by...
       </p>
	 <ul>
	   <li class=\"inline\"><a class=\"nohist\" href=\"http://tcdb.grinnell.edu/map?tab_select=2\">Toner Level (default)</a></li>
	   <li class=\"inline\"><a class=\"nohist\" href=\"http://tcdb.grinnell.edu/map?tab_select=2&amp;sort_type=ksort\">Printer Name</a></li>
	 </ul>\n";

// First, we should see if the $_GET['sort_type'] variable has been set. If it hasn't, we should present the default...

$sort = 'arsort';

if (isset($_GET['sort_type'])) {
	$sort = $_GET['sort_type'];
}

else {
	// Default -- sort type is 'arsort'
}

// And finally, sort!

$sort ($printer_toner);

print '<p class="obl">';

foreach ($printer_toner as $printer_name => $toner_level) {
	if ($toner_level <= 3 || ${"{$printer_string}_paper_status"} == 1) {
		$class = "red";
	}

	else {
		$class = "normal";
	}

	// Check if the file is empty. If it is, print an out-of-order message

	if (empty($toner_level)) {
		print "<span class=\"$class\">$printer_name is out of order</span><br />\n";
	}
	else if (${"{$printer_string}_paper_status"} == 1) {
		print "<span class=\"$class\">$printer_name is out-of-paper</span><br />\n";
        }
	else {
		print "<span class=\"$class\">$printer_name has $toner_level% toner</span><br />\n";
	}
}

print "</p>\n";

print "<p>You can find historical out-of-order statistics on these printers <a href=\"oo_stats/oo_stats.php\">here</a></p>";

/* Do Google Chart API stuff

$hsize = 250 ;
$vsize = 100 ;
$chart_type = 'p3' ; */

// The Google chart stuff led to malformed XHTML -- probably because I need to urlencode the string. Whoops.
// Just use &amp; for &

/* print "<p><a href=\"http://chart.apis.google.com/chart?
chs=$hsize
x$vsize
&chd=t:60,40
&cht=$chart_type
&chl=Hello|World\">Google Chart</a></p>"; */

// The following is an array that functions as an "ip table"
// correspond to the closest lab geographically. This is from [gerpheid] and
// [satherdy]'s excursion in 2008, and should really be verified by [ellisd]

/* Also, this should be moved to the lab_search info

	$ip_table = array (
	'1' => 'Cleveland is the closest lab',
	'187' => 'Cleveland is the closest lab',
	'188' => 'Cleveland and Read are both close',
	'186' => 'Read and Lazier are both close',
	'0' => 'Younker is the closest lab',
	'166' => 'Younker is the closest lab',
	'164' => 'Younker is the closest lab',
	'162' => 'Norris is the closest lab',
	'165' => 'Norris is the closest lab',
	'221' => 'Lazier is the closest lab',
	'220' => 'Lazier is the closest lab');
	
	print "<p class=\"obl\">
	Your IP Address is $ip
	<br />
	Your subnet is $subnet[2]
	</p>\n"; */


/* A litte php to print the date and time...

	print '<p class="obl">It is ';

	print date( 'l, Y-m-d' );

	print ' and the time is '; 

	print date( 'H:i:s' );

	print "</p>\n"; */

print "<p class=\"obl\">Did you know that you can <a href=\"http://tcdb.grinnell.edu/wiki/pmwiki.php?n=Help.NetworkPrinting\">print</a> to any of these printers from your room?</p>\n";

?>
